﻿using Teigha.TD;

namespace OdaOperation.Core.Creators
{
    /// <summary>
    /// 抽象基类，用于创建对象
    /// </summary>
    public abstract class BaseCreator
    {
        // 数据库对象
        protected OdDbDatabase m_database;

        // 图层名称
        protected string m_layerName;

        // 块表对象ID
        protected OdDbObjectId m_blockTableId;

        /// <summary>
        /// 获取当前活动块
        /// </summary>
        /// <returns></returns>
        protected OdDbObjectId GetActiveBlock()
        {
            // 获取当前布局的块表记录ID
            OdDbObjectId odDbObjectId = m_database.getActiveLayoutBTRId();

            // 如果当前布局为图纸空间
            if (odDbObjectId == m_database.getPaperSpaceId())
            {
                // 获取当前活动视口对象
                OdDbViewport odDbViewport = m_database.activeViewportId().safeOpenObject() as OdDbViewport;
                // 如果当前活动视口数量大于1
                if (odDbViewport.number() > 1)
                {
                    // 返回模型空间的块表记录ID
                    odDbObjectId = m_database.getModelSpaceId();
                }
            }

            return odDbObjectId;
        }

        /// <summary>
        /// 构造函数，初始化数据库对象
        /// </summary>
        /// <param name="pDb"></param>
        public BaseCreator(OdDbDatabase pDb)
        {
            m_database = pDb;
        }

        /// <summary>
        /// 构造函数，初始化数据库对象和块表对象ID
        /// </summary>
        /// <param name="pDb"></param>
        /// <param name="blockTableId"></param>
        public BaseCreator(OdDbDatabase pDb, OdDbObjectId blockTableId)
        {
            m_database = pDb;
            m_blockTableId = blockTableId;
        }

        /// <summary>
        /// 构造函数，初始化数据库对象、块表对象ID和图层名称
        /// </summary>
        /// <param name="pDb"></param>
        /// <param name="blockTableId"></param>
        /// <param name="layerName"></param>
        public BaseCreator(OdDbDatabase pDb, OdDbObjectId blockTableId, string layerName)
        {
            m_database = pDb;
            m_blockTableId = blockTableId;
            m_layerName = layerName;
        }

        /// <summary>
        /// 构造函数，初始化数据库对象和图层名称
        /// </summary>
        /// <param name="pDb"></param>
        /// <param name="layerName"></param>
        public BaseCreator(OdDbDatabase pDb, string layerName)
        {
            m_database = pDb;
            m_layerName = layerName;
        }
    }

}

